const express = require("express")
const router = require("./02router")
//引入第三方中间件cors
const cors = require("cors")
const app = express()
//jsonp接口要写在cors前
app.get("/api/jsonp",(req,res)=>{
    const fullName = req.query.callback
    const data = {"name":'张三',"age":20,"gender":"男"}
    const scriptStr = `${fullName}${JSON.stringify(data)}`
    res.send(scriptStr)
})


//注册cors 中间件到app,要在所以路由前配置
app.use(cors())
//引入中间件解析表单数据的中间件
app.use(express.urlencoded({extended:false}))


app.use("/api",router)

app.listen(8080)